<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Label Printing</title>

		<style type="text/css" title="currentStyle">
			@import "./media/css/demo_page.css";
			@import "./media/css/demo_table.css";
			@import "./themes/smoothness/jquery-ui-1.8.4.custom.css";
		.decoinput {
	background-color: #C6F3FF;
	text-transform:capitalize;
	border-style:solid;
	border-color:#036;
	border-width:1px;
}
        </style>
<script type="text/javascript" language="javascript" src="./media/js/jquery.js"></script>
		<script type="text/javascript" language="javascript" src="./media/js/jquery.dataTables.js"></script>
		<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
	oTable = $('#example').dataTable({
		"bJQueryUI": true,
		"sPaginationType": "full_numbers"
	});
} );
		</script>

</head>
<body style="text-transform:capitalize;">
<?php
function checkEbayFileHeader($fileName){
if(file_exists($fileName)){
	$fl=fopen($fileName,"r");
	$firstline = fgets($fl);
	$ebayFirstLine="Sales Record Number,User Id,Buyer Fullname,Buyer Phone Number,Buyer Email,Buyer Address 1,Buyer Address 2,Buyer City,Buyer State,Buyer Zip,Buyer Country,Order ID,Item ID,Transaction ID,Item Title,Quantity,Sale Price,Shipping And Handling,Sales Tax,Insurance,Total Price,Payment Method,PayPal Transaction ID,Sale Date,Checkout Date,Paid on Date,Shipped on Date,Shipping Service,Feedback Left,Feedback Received,Notes to Yourself,Custom Label,Variation Details";
	if(strcmp($ebayFirstLine,trim($firstline))==0 ){
		return true;
		}	
	}
	return false ;
}
	
	
$bigarr= array();
$counter=0;
$errorflag=0;
$username="test"; //get user name from cookie 
date_default_timezone_set('Australia/Melbourne'); //Set Default time zone by user selection 
$dateToday = date("Y_m_d");
$uploadfolder = './';
$csvsfolder = "./csvs/";
$filename = $_GET['filename'];
$token = uniqid();
//echo $useruploadedfilename = $dateToday."_".$username."_".$token.".csv";

//if(move_uploaded_file($_FILES['useruploadfile']['tmp_name'],$uploadfolder.$useruploadedfilename)) {
	
//	if(!checkEbayFileHeader($uploadfolder.$useruploadedfilename)){
		//$errorflag=1;
//		}
		
	//then check it is correct ebay file structure 
	

//if($errorflag==0){
$orgFile=fopen($csvsfolder.$filename,"r"); // read only 
			while(($lineData = fgetcsv($orgFile,0))!= FALSE){
				
				$packingMethod = file_get_contents('http://192.168.1.124/online/get-packing-method/barcode/'.$lineData[31]);
									
				if($counter>0)
				{
				$labarr=array_fill(0,9," ");				
				$labarr[0] = strtolower($lineData[0]);//order No
				$labarr[1] = strtolower($lineData[27]);	//post way
				$labarr[2] = strtolower($lineData[14]);	//title
				$labarr[3] = strtolower($lineData[2]);	//customer name
				$labarr[4] = strtolower($lineData[1]);	//ebay id
				$labarr[5] = strtolower($lineData[5]);	//address 1
				$labarr[6] = strtolower($lineData[6]);	//address2
				$labarr[7] = strtolower($lineData[7]);  //city
				$labarr[8] = strtolower($lineData[8]);	//state
				$labarr[9] = strtolower($lineData[9]);	//postcode	
				$labarr[10] = strtoupper($lineData[15]." x ".$lineData[31].$packingMethod);
				$bigarr[]=$labarr;
				}
				$counter++;
			}
?>
<form action="./eb2.php" method="post" name="form">
<table border="0" cellspacing="0" cellpadding="0" id="example">

<thead>  
  <tr>
    <td>Print This</td>
    <td>Quantity</td>
    <td>SRN #</td>
    <td>User id</td>
    <td>Name</td>
    <td>Address <br /> Line1</td>
    <td>Address <br /> Line2</td>
    <td>City</td>
    <td>State</td>
    <td>Post Code</td>
    <td>Product <br />Title</td>
    <td>Qty/Code</td>
  </tr>
 </thead>
 <tbody>
<?php
$counter=0;
foreach($bigarr as $lineArr)
{
?>
  <tr>
    <td>
    <input name="counter<?php echo $counter;?>" type="hidden" value="<?php echo $counter;?>">
    <input name="choice<?php echo $counter;?>" type="checkbox" value="1" 
    <?php if(strlen($lineArr[4])){ ?>
    checked="checked" 
    <?php }?>
    
    
    /></td>
    <td><select name="qt<?php echo $counter;?>" size="1">
      <option selected="selected" value="1">1</option>
      <option value="2">2</option>
      <option value="3">3</option>
    </select></td>
    <td><input name="orderNO<?php echo $counter;?>" type="text" value="<?php echo $lineArr[0];?>" /></td>
    <td><input class="decoinput" name="userID<?php echo $counter;?>" type="text" value="<?php echo $lineArr[4];?>" /></td>
    <td><input class="decoinput" name="userName<?php echo $counter;?>" type="text" value="<?php echo $lineArr[3];?>" /></td>
    <td><input class="decoinput" name="addrLine1<?php echo $counter;?>" type="text" value="<?php echo $lineArr[5];?>" /></td>
    <td><input class="decoinput" name="addrLine2<?php echo $counter;?>" type="text" value="<?php echo $lineArr[6];?>" /></td>
    <td><input class="decoinput" name="addrCity<?php echo $counter;?>" type="text" value="<?php echo $lineArr[7];?>" /></td>
    <td><input class="decoinput" name="addrState<?php echo $counter;?>" type="text" value="<?php echo $lineArr[8];?>" /></td>
    <td><input class="decoinput" name="postCode<?php echo $counter;?>" type="text" value="<?php echo $lineArr[9];?>" /></td>
    <td><input class="decoinput" name="Title<?php echo $counter;?>" type="text" value="<?php echo $lineArr[2];?>" /></td>
    <td><input class="decoinput" name="qty<?php echo $counter;?>" type="text" value="<?php echo $lineArr[10];?>" /></td>
  </tr>
<?php
$counter++;
}
//}
//}
?>  
</tbody>
<tfoot>  
  <tr>
    <td>Check</td>
    <td>Qt</td>
    <td>eBay Order #</td>
    <td>User id</td>
    <td>Name</td>
    <td>Add1</td>
    <td>Add2</td>
    <td>City</td>
    <td>State</td>
    <td>PCode</td>
    <td>Title</td>
    <td>Qty/Code</td>
  </tr>
 </tfoot>
 
</table>
<input type="submit" value="submit" />
</form>  

</body>
</html>